<script>
	$(document).ready(function () {
		//前端校验
		var formId = "${formId!}"; 	
		var divId = "${divId!}"; 
		var modalId = "${modalId!}"; 
		if(divId!=''&&divId){
			$("#"+formId).validate({     
				 submitHandler: function(form) 
				   {      
					 if(modalId!=''&&modalId){
						 ajaxModalForm(modalId,divId, formId);
					 }else{
						 ajaxForm(divId, formId);
					 }
				     
				   }  
				 })			
		}else{
			$("#"+formId).validate();
		}

		//后台校验结果处理
		setErrorMsg(${errorMsgJson!});
		//保持原先输入的值
		keepPara(${reqParaJson!});
	})
	
	function setErrorMsg(errorMsgJson){
		if(errorMsgJson){
			console.log("error string :"+JSON.stringify(errorMsgJson));
	 		for(var error in errorMsgJson){
	 			var errorKey = error;
	 			var errorMsg = errorMsgJson[error];
	 			var input = $("input[name='"+errorKey+"']");
	 			input.addClass('help-block m-b-none');
	 			input.attr('aria-describedby',errorKey.replace(".","\\.")+'-error');
	 			input.attr('aria-invalid','true');
	 			input.after('<span id="'+errorKey+'-error" class="help-block m-b-none">'+errorMsg+'</span>');
	 			input.closest("div").addClass("has-error");
			} 			
		}

	}
	
	function keepPara(reqParaJson){
		if(reqParaJson){
			console.log("reqPara string :"+JSON.stringify(reqParaJson));
	 		for(var reqPara in reqParaJson){
	 			var filedName = reqPara;
	 			var value = reqParaJson[reqPara];
	 			$("[name='"+filedName+"']").val(value);
			} 			
		}

	}	
</script>	
